//
//  CYLPlusDemoChildViewController.m
//  CYLTabBarController
//
//  Created by chenyilong on 19/12/2017.
//  Copyright © 2017 微博@iOS程序犭袁. All rights reserved.
//

#import "CYLPlusDemoChildViewController.h"
#import "Category_product_vc.h"
#import "App_category.h"

@interface CYLPlusDemoChildViewController ()
@property (nonatomic, assign)BOOL needRetry;
@end

@implementation CYLPlusDemoChildViewController

//重载init方法
- (instancetype)init
{
    if (self = [super initWithTagViewHeight:59])
    {
        self.selectedTitleColor = themeColor;
        self.selectedIndicatorColor = themeColor;
        
    }
    return self;
}




- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加智能家具";
    
    
    //设置自定义属性
    self.tagItemSize = CGSizeMake(110, 49);
    
        self.selectedIndicatorSize = CGSizeMake(3, 15);
    //    self.selectedTitleColor = [UIColor blueColor];
    //    self.selectedTitleFont = [UIFont systemFontOfSize:18];
    
    //    self.graceTime = 15;
    //    self.gapAnimated = YES;
    
    self.backgroundColor = [UIColor whiteColor];
    
  
    [self net_req];

}

- (void)net_req{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"Authorization"];
    [dict setObject:app_code forKey:@"app_code"];

    [PPHTTPRequest req:@"api/App/category" parameters:dict success:^(id response) {
        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
        if ([error_code isEqualToString:@"0"]) {
            App_category *category = [App_category mj_objectWithKeyValues:response];
            [self reloadWith:category];
        }
        
        else
            //            if ([error_code isEqualToString:@""])
        {
            
            [MBProgressHUD showTipMessageInView:response[@"error_msg"]];
            self.needRetry = YES;
        }
    } failure:^(NSError *error) {
        [MBProgressHUD showTipMessageInView:[error localizedDescription]];
        self.needRetry = YES;

    }];
}
- (void)reloadWith:(App_category *)cat{
    
    
    
    NSMutableArray *titleArray = [NSMutableArray array];
    NSMutableArray *params = [NSMutableArray array];
    NSMutableArray *classNames = [NSMutableArray array];


    
    for (App_categoryData *d in cat.data) {
        [titleArray addObject: d.category_name];
        if (!d.product_list) {
            [params addObject:@[]];
        }else{
            [params addObject:d.product_list];
            self.needRetry = NO;

        }
        
        [classNames addObject:Category_product_vc.class];
    }
    
    [self reloadDataWith:titleArray andSubViewdisplayClasses:classNames withParams:params];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if (self.needRetry) {
        [self net_req];
    }
}

- (void)dealloc {
    NSLog(@"🔴类名与方法名：%@（在第%@行），描述：%@", @(__PRETTY_FUNCTION__), @(__LINE__), @"");
}


@end
